//
// Created by xili on 2024/8/5 20:44.
// Go big or go home.
//
#include <vector>

using namespace std;

class Solution {
public:
    int maxProductDifference(vector<int> &nums) {
        //维持最大，第二大，最小，第二小的值
        int n = nums.size();
        int mx1 = 0, mx2 = 0, mn1 = 10001, mn2 = 10001;
        for (int i = 0; i < n; i++) {
            if (nums[i] > mx1) {
                mx2 = mx1;
                mx1 = nums[i];
            } else if (nums[i] > mx2) {
                mx2 = nums[i];
            }
            if (nums[i] < mn1) {
                mn2 = mn1;
                mn1 = nums[i];
            } else if (nums[i] < mn2) {
                mn2 = nums[i];
            }
        }
        return (mx1 * mx2) - (mn1 * mn2);
    }
};